#include <iostream>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int **zone = new int *[n];
    for (int i = 0; i < n; ++i) {
        int *line = new int[n];
        for (int j = 0; j < n; ++j) {
            cin >> line[j];
        }
        zone[i] = line;
    }

    int m = 0;
    for (int i = 0; i < n - k + 1; ++i) {
        for (int j = 0; j < n - k + 1; ++j) {
            int curr = 0;
            for (int l = 0; l < k; ++l) {
                for (int i1 = 0; i1 < k; ++i1) {
                    curr += zone[i + l][j + i1];
                }
            }
            if (curr > m) {
                m = curr;
            }
        }
    }
    cout << m << endl;
}